* {
  margin: 0;
  box-sizing: border-box;
}
*:not(select) {
  /* SELECT retains sensible minimum padding in Chrome but not in Firefox */
  padding: 0;
}

:root {
  font: 14px menu;
  --bg: var(--fill-0);
  --fg: var(--fill-15);
  --fill-0: #fff;
  --fill-0-5: #f7f7f7;
  --fill-1: #eee; // step = 0x11
  --fill-2: #ddd;
  --fill-3: #ccc;
  --fill-4: #bbb;
  --fill-5: #aaa;
  --fill-6: #999;
  --fill-7: #888;
  --fill-8: #777;
  --fill-9: #666;
  --fill-10: #555;
  --fill-11: #444;
  --fill-12: #333;
  --fill-13: #222;
  --fill-14: #111;
  --fill-15: #000;
  --tooltip-color: white;
  --tooltip-bg: rgba(0,0,0,.8);
  --tooltip-border-color: transparent;
  --focus-border-color: var(--fill-12);
  @media (prefers-color-scheme: dark) {
    --fg: var(--fill-11);
    --fill-0: #1e1e1e;
    --fill-0-5: #262626;
    --fill-1: #2d2d2d; // step = 0x0F
    --fill-2: #3c3c3c;
    --fill-3: #4b4b4b;
    --fill-4: #5a5a5a;
    --fill-5: #696969;
    --fill-6: #787878;
    --fill-7: #878787;
    --fill-8: #969696;
    --fill-9: #a5a5a5;
    --fill-10: #b4b4b4;
    --fill-11: #c3c3c3;
    --fill-12: #d2d2d2;
    --fill-13: #e1e1e1;
    --fill-14: #f0f0f0;
    --fill-15: #ffffff;
    --tooltip-border-color: #8888;
    --scrollbar-bg: #1a1a1a;
    --input-bg: #111;
  }
}

body {
  // overflow: hidden; // avoid flash of viewport caused by tooltip
  font-size: 1rem;
  background: var(--bg);
  color: var(--fg);
}

// Form elements will not inherit
body,
button,
select,
input,
textarea {
  font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 1rem;
}

h1 {
  font-size: 1.5rem;
}
h2 {
  font-size: 1.3rem;
}
h3 {
  font-size: 1.1rem;
}
h1, h2, h3 {
  margin-top: 1em;
  margin-bottom: .5em;
}
a {
  color: dodgerblue;
  text-decoration: none;
  @media (prefers-color-scheme: dark) {
    color: #7baaff;
  }
  &:focus,
  &:hover {
    text-decoration: underline;
  }
}
span:focus {
  text-decoration: underline;
}
hr {
  margin: .5rem 0;
  border-style: solid;
  border-width: 1px 0 0 0;
}
input[type=checkbox] {
  margin-right: .2em;
  &:focus + * {
    text-decoration: underline;
  }
}
button,
input,
select,
textarea {
  border: 1px solid var(--fill-3);
  &:focus {
    border-color: var(--focus-border-color);
  }
}
input[disabled] ~ * {
  opacity: .5;
}
input[type=text],
input[type=url],
input[type=search],
input[type=number],
input[type=password] {
  &[disabled] {
    background: var(--fill-1);
    cursor: not-allowed;
  }
}
select {
  field-sizing: content;
}
textarea {
  display: block;
  width: 100%;
}
input[type=text],
input[type=url],
input[type=search],
input[type=number],
input[type=password],
textarea {
  padding: 0 .2em;
}
kbd,
code {
  padding: 0 .2em;
  background: hsla(45, 75%, 75%, .25);
  @media (prefers-color-scheme: dark) {
    background: hsla(40, 100%, 50%, .2);
  }
}

fieldset {
  display: inline-block;
  padding: .5rem;
  border: 1px solid var(--fill-3);
}

:focus {
  outline: none;
}

.icon {
  width: 1rem;
  height: 1rem;
}

// Firefox does not support `svg path` selector
svg {
  fill: currentColor;
}

button {
  border: 1px solid var(--fill-5);
  background: var(--fill-1);
  @media (prefers-color-scheme: dark) {
    background: var(--fill-2);
  }
  color: var(--fg);
  &:not([disabled]):hover {
    border-color: var(--fill-7);
  }
  &:active {
    background: var(--fill-5);
  }
  &[disabled] {
    opacity: .5;
  }
  &:not([disabled]) {
    cursor: pointer;
  }
}

button,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  padding: 0 .5rem;
  font-size: 1rem;
  line-height: 1.5;
  vertical-align: bottom;
  &,
  &:hover,
  &:focus {
    text-decoration: none;
  }
}
.btn-ghost {
  color: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  &:focus,
  &:hover {
    border-color: var(--fill-5);
    background: var(--bg);
  }
  > .icon {
    display: block;
    height: 2rem;
  }
  &.active {
    background: var(--fill-1);
    border-color: var(--fill-4);
  }
  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}
.btn-danger {
  color: #f00;
}

a[tabindex="0"] {
  cursor: pointer;
}
a:not([href]):hover {
  text-decoration: none;
}

.sep {
  display: inline-block;
  padding: 0 .5rem;
  font-size: 1rem;
  line-height: 1;
  &::after {
    content: '';
    display: inline-block;
    height: 1em;
    border-right: 1px solid var(--fill-4);
  }
}

ul,
ol {
  padding-left: 20px;
}
li {
  line-height: 1.4;
}

.inline-block {
  display: inline-block;
}
.flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.flex-wrap {
  flex-wrap: wrap;
}
.flex-auto {
  flex: auto;
  .flex-col > & {
    height: 0;
  }
  :not(.flex-col) > & {
    width: 0;
  }
}
.flex-1 {
  flex: 1;
}
.center-items {
  align-items: center;
}
.stretch-self {
  align-self: stretch;
}
.pos-rel {
  position: relative;
}
.ml-1, .ml-1c > :nth-child(n + 2) {
  margin-left: .5em;
}
.mr-1, .mr-1c > :nth-last-child(n + 2) {
  margin-right: .5em;
}
.ml-2, .ml-2c > :nth-child(n + 2) {
  margin-left: 1em;
}
.mr-2, .mr-2c > :nth-last-child(n + 2) {
  margin-right: 1em;
}
.mt-0, .mt-0c > :nth-child(n + 2) {
  margin-top: 0;
}
.mt-1, .mt-1c > :nth-child(n + 2) {
  margin-top: .5em;
}
.mb-1, .mb-1c > :nth-last-child(n + 2) {
  margin-bottom: .5em;
}
.mb-2, .mb-2c > :nth-last-child(n + 2) {
  margin-bottom: 1em;
}
.mx-1, .mx-1c > * {
  margin-left: .5em;
  margin-right: .5em;
}
.my-1, .my-1c > * {
  margin-top: .5em;
  margin-bottom: .5em;
}
.h-screen {
  height: 100vh;
}
.h-100 {
  height: 100%;
}
.w-100 {
  width: 100%;
}
.w-1 {
  width: 4em;
}
.fixed-full {
  position: fixed;
}
.abs-full {
  position: absolute;
}
.fixed-full,
.abs-full {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.ellipsis {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}
.scroll-y {
  overflow-y: auto;
}
.subtle {
  color: var(--fill-7);
}

.frame {
  background: var(--fill-1);
  &-block {
    padding: .5rem;
  }
}

.editor-code .CodeMirror {
  height: 100%;
}

code,
.monospace-font,
.editor-code .CodeMirror,
.CodeMirror-hints.default /* CSS specificity hack to override default CM style */ {
  /* Use `Courier New` to ensure `&nbsp;` has the same width as an original space. */
  font-family: "Fira Code", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace;
}

body .vl-tooltip {
  z-index: 10000;
  > i {
    color: var(--tooltip-bg);
    z-index: 1;
  }
  &-content {
    margin: -1px;
    border: 1px solid var(--tooltip-border-color);
    color: var(--tooltip-color);
    background: var(--tooltip-bg);
  }
}

.vl-dropdown-menu {
  padding: .5rem;
  border: 1px solid var(--fill-4);
  background: var(--bg);
}

.modal-content {
  margin: 0 auto;
  padding: 1rem;
  background: var(--bg);
  box-shadow: 0 0 40px #000;
}

.has-error,
.btn-ghost.has-error,
input[type].has-error {
  // reminder: make sure all colors are readable in light/dark schemes
  border-color: #8008;
  background: #f002;
  &:focus {
    border-color: #f008;
  }
}

.scary-switch:checked {
  accent-color: red;
  & + span {
    color: red;
  }
}

@media (prefers-color-scheme: dark) {
  input[type="radio"]:not(:checked),
  input[type="checkbox"]:not(:checked) {
    filter: invert(1);
  }
  input[type="text"],
  input[type="url"],
  input[type="search"],
  input[type="number"],
  input[type="password"],
  select,
  textarea {
    background: var(--input-bg);
    color: var(--fg);
    border: 1px solid var(--fill-3);
    &:focus {
      border-color: var(--focus-border-color);
    }
  }
  ::-webkit-scrollbar {
    width: 14px;
    height: 14px;
    background: var(--scrollbar-bg);
    &-button:single-button {
      background: radial-gradient(circle at center, #333 40%, var(--scrollbar-bg) 40%);
      &:hover {
        background: radial-gradient(circle at center, #444 40%, var(--scrollbar-bg) 40%);
      }
      &:active {
        background: radial-gradient(circle at center, #555 40%, var(--scrollbar-bg) 40%);
      }
    }
    &-track-piece {
      background: #333;
      border: 4px solid var(--scrollbar-bg);
      border-radius: 8px;
      &:hover {
        background: #444;
      }
      &:active {
        background: #555;
      }
    }
    &-thumb {
      border: 3px solid var(--scrollbar-bg);
      border-radius: 8px;
      background: #555;
      &:hover {
        background: #666;
      }
      &:active {
        background: #777;
      }
    }
  }
  ::-webkit-resizer {
    background: var(--input-bg) linear-gradient(-45deg,
      transparent 3px, #888 3px, #888 4px, transparent 4px,
      transparent 6px, #888 6px, #888 7px, transparent 7px) no-repeat;
    border: 2px solid transparent;
  }
  :-webkit-autofill {
    box-shadow: 0 0 0 1000px var(--input-bg) inset;
    -webkit-text-fill-color: #fff;
  }
}

@media (min-width: 768px) {
  .visible-sm {
    display: none;
  }
}

@media (max-width: 550px) { /* This value is also used in other files */
  .hidden-sm {
    display: none !important;
  }
}

@media (max-width: 319px) {
  .hidden-xs {
    display: none !important;
  }
}
